package com.iweb.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author jay
 * @date 2021/9/3
 * @desc 统一编码设置的过滤器
 */
@WebFilter(filterName = "encodingFilter", urlPatterns = {"*.jsp", "*.do"})
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("编码过滤器工作中.....");

        servletRequest.setCharacterEncoding("utf-8");
//        servletResponse.setContentType("text/html;charset=utf-8");
        // 继续访问其他资源
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
